//
//  StrategyInspectionResult.m
//  StrategySimulator
//
//  Created by jiro on 12/07/16.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "StrategyPerfomance.h"

#import "../Commons.h"

NSString* StrategyPerfomance::tableName()
{
	return kText_StrategyPerfomance;
}

NSString* StrategyPerfomance::queryCreateTable()
{
	NSString* s = [ NSString stringWithFormat: 
		@"create table %@ ( %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@( %@, %@ ) );",
		kText_StrategyIndex, kText_Integer,
		kText_ParameterIndex, kText_Integer,
		kText_TradeCount, kText_Integer,
		kText_WinRate, kText_Real,
		kText_InterestRate, kText_Real,
		kText_ProfitPerTrade, kText_Real,
		kText_DayIntervalPerTrade, kText_Real,
		kText_PrimaryKey, kText_StrategyIndex, kText_InspectParameterIndex ];
	return s;
}

NSString* StrategyPerfomance::querySelectAll( const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelectAll( tableName(), clauses );
	return s;
}

NSString* StrategyPerfomance::querySelect( const std::vector< FieldNode >& fieldNodes, const std::vector< ClauseNode >& clauses )
{
	NSString* s = DbTableEntry::querySelect( fieldNodes, tableName(), clauses );
	return s;
}

NSString* StrategyPerfomance::queryInsert() const
{
	NSString* s = [ NSString stringWithFormat: @"insert into %@ values %@;",
		tableName(), queryInsertValue() ];
	return s;
}

NSString* StrategyPerfomance::queryInsertValue() const
{
	NSString* s = [ NSString stringWithFormat: @"( %d, %d, %d, %f, %f, %f, %f )",
		strategyIndex,
		parameterIndex,
		tradeCount,
		winRate,
		interestRate,
		profitPerTrade,
		dayIntervalPerTradeDay ];
	return s;
}

StrategyPerfomance::StrategyPerfomance()
{
}

StrategyPerfomance::StrategyPerfomance( const std::vector< const char* >& values )
{
	strategyIndex = atoi( values[ 0 ] );
	parameterIndex = atoi( values[ 1 ] );
	tradeCount = atoi( values[ 2 ] );
	winRate = atof( values[ 3 ] );
	interestRate = atof( values[ 4 ] ); 
	profitPerTrade = atof( values[ 5 ] );
	dayIntervalPerTradeDay = atof( values[ 6 ] );
}

double StrategyPerfomance::getScore() const
{
	return interestRate;
}

NSString* StrategyPerfomance::toString() const
{
	NSString* s = [ NSString stringWithFormat: 
		@"strategyIndex: %d, "
		@"inspectParameterIndex: %d, "
		@"tradeCount: %d, "
		@"winRate: %f, "
		@"interestRate: %f, "
		@"profitPerTrade: %f, "
		@"dayIntervalPerTrade: %f",
		strategyIndex,
		parameterIndex,
		tradeCount,
		winRate,
		interestRate,
		profitPerTrade,
		(double) dayIntervalPerTradeDay
	];
	return s;
}
